#include "StdAfx.h"
#include "ZCaiwuItemCtrl.h"
#include "..\..\..\ZAllTools\ZTools\ZGlobalTools.h"
#include "..\ZWuliuSvr\DBOpt\ZWuliuDefine.h"

ZCaiwuItemCtrl::ZCaiwuItemCtrl(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	ui.lineEdit_jine->setValidator(new QDoubleValidator(this));
	ui.comboBox_state->addItem(WuliuCaiwu_QingZhang);
	ui.comboBox_state->addItem(WuliuCaiwu_QianShou);
	ui.comboBox_state->addItem(WuliuCaiwu_QianFu);
}

ZCaiwuItemCtrl::~ZCaiwuItemCtrl()
{

}

QString ZCaiwuItemCtrl::text()
{
	QString sVal;
	return sVal;
}

void ZCaiwuItemCtrl::setText( const QString& sText )
{
	ui.label->setText(sText);
}

QString ZCaiwuItemCtrl::getValStr()
{
	return ui.label->text() + ZSplitStr_Sharp +
		ui.lineEdit_jiesuanren->text() + ZSplitStr_Sharp + 
		ui.comboBox_state->currentText() + ZSplitStr_Sharp +
		ui.lineEdit_jine->text() + ZSplitStr_Sharp + 
		ui.lineEdit_tips->text();
}

bool ZCaiwuItemCtrl::setValStr( const QString& sVal, const QString& sLabelText )
{
	if (sVal.length() < 1)
	{
		ui.label->setText(sLabelText);
		ui.lineEdit_jiesuanren->setText("");
		ui.comboBox_state->setCurrentIndex(ui.comboBox_state->findText(WuliuCaiwu_QingZhang));
		ui.lineEdit_jine->setText("");
		ui.lineEdit_tips->setText("");
		return true;
	}

	vecStr subStr = ZGlobalTool::SplitStr_NoTrim(sVal, ZSplitStr_Sharp);
	if (subStr.size() != 5)
	{
		Q_ASSERT(false);
		return false;
	}

	ui.label->setText(subStr[0]);
	ui.lineEdit_jiesuanren->setText(subStr[1]);
	ui.comboBox_state->setCurrentIndex(ui.comboBox_state->findText(subStr[2]));
	ui.lineEdit_jine->setText(subStr[3]);
	ui.lineEdit_tips->setText(subStr[4]);
	return true;
}

void ZCaiwuItemCtrl::setShuZhiVal(const QString& sVal)
{
	ui.lineEdit_jine->setText(sVal);
}
